home *** CD-ROM | disk | FTP | other *** search
/ Hot Super Models / Hot Super Models.iso / unix / x11 / xv200.tar / xv-2.00 / unsupt / macpaint next >
Text File  |  1992-01-01  |  8KB  |  297 lines

  1. ::::::::::::::
  2. inbox/10
  3. ::::::::::::::
  4. Return-Path: markm@sequent.com
  5. Posted-Date: Thu, 24 Oct 91 11:42:09 -0700
  6. Received-Date: Thu, 24 Oct 91 14:43:16 EDT
  7. Received: from time1.sequent.com by gateway.sequent.com (5.61/1.34)
  8.     id AA07639; Thu, 24 Oct 91 11:44:04 -0700
  9. Received: by time1.sequent.com (5.61/1.34)
  10.     id AA10311; Thu, 24 Oct 91 11:42:09 -0700
  11. Date: Thu, 24 Oct 91 11:42:09 -0700
  12. From: Mark Ed Majhor <markm@sequent.com>
  13. Message-Id: <9110241842.AA10311@time1.sequent.com>
  14. To: bradley@grip.cis.upenn.edu
  15. Subject: Re: Hi (I am an xv user) (here is xvmac.c)
  16.  
  17. John - thanks for the jpeg contact.  I have his reader already and it
  18. works fine.  Here is the mac stuff.  I did this for xloadimage also
  19. and just converted it for xv.  The code originally came out of FBM
  20. by patrick naughton.
  21. -------------------  cut here -------- cut here ---------   cut here ---
  22.  
  23. /*
  24.  * I don't need to tell you how to add this (here is the xv.c lines).
  25.  
  26. #define MAC (NEXT NUMBER)
  27.  
  28.   else if (magicno[0] == 0x0) filetype = MAC;
  29.  
  30.   case MAC:  i = LoadMAC(filename,ncols); break;
  31.  
  32. */
  33.  
  34. /*
  35.  * xvmac.c:
  36.  *
  37.  * adapted from code by Patrick Naughton (naughton@sun.soe.clarkson.edu)
  38.  *
  39.  * xvmac.c
  40.  * Mark Majhor
  41.  * February 1991
  42.  *
  43.  * routines for reading MAC files
  44.  *
  45.  * LoadMAC(fname) - loads a mac image file
  46.  */
  47. # include <stdio.h>
  48. # include <math.h>
  49. # include <ctype.h>
  50. # include "xv.h"
  51. # include "mac.h"
  52.  
  53. # define NEXTBYTE (*ptr++)
  54.  
  55. /****
  56.  **
  57.  ** local variables
  58.  **
  59.  ****/
  60.  
  61. static int  mac_img_width;        /* image width */
  62. static int  mac_img_height;        /* image height */
  63. static int  mac_img_depth;        /* image depth */
  64. static int  mac_img_planes;        /* image planes */
  65. static int  mac_img_BPL;        /* image bytes per line */
  66. static byte *ptr;            /* raw data ptr */
  67.  
  68. /****
  69.  **
  70.  ** global variables
  71.  **
  72.  ****/
  73.  
  74. byte *RawMAC;                /* raw data file heap */
  75.  
  76. /*
  77.  * open MAC image in the input stream; returns MACIN_SUCCESS if
  78.  * successful. (might also return various MACIN_ERR codes.)
  79.  */
  80. static int mac_read_header(s)
  81. FILE *s;
  82. {
  83.   int c, i, len, mhsum = 0;
  84.  
  85.   /*
  86.    * the mac paint files that came with xmac had an extra
  87.    * 128 byte header on the front, with a image name in it.
  88.    * true mac paint images don't seem to have this extra
  89.    * header.  The following code tries to figure out what
  90.    * type the image is and read the right amount of file
  91.    * header (512 or 640 bytes).
  92.    */
  93.   /*
  94.    * if mhsum = 0 this is probably a
  95.    * a g3 fax file.
  96.    */
  97.   for (i = 0; i < 10; i++) mhsum += RawMAC[i];
  98.  
  99.   if ((RawMAC[0] != MAC_MAGIC) /* || (mhsum == 0) */)
  100.     return MACIN_ERR_BAD_SD;
  101.  
  102.   /* 
  103.    * Get image name  (if available)
  104.    * if byte 1 of header is not 0
  105.    * then it is the length of a image
  106.    * name string.  Also the remaining
  107.    * header length is MAC_HDR_LEN (512) +
  108.    * ADD_HDR_LEN (128).
  109.    */
  110.  
  111.   /*
  112.    * ptr now points to the beginning
  113.    * of the raw data in RawMac.
  114.    */
  115.   if (RawMAC[1] != 0)        /* if name header */
  116.     ptr = &RawMAC[MAC_HDR_LEN + ADD_HDR_LEN];
  117.   else
  118.     ptr = &RawMAC[MAC_HDR_LEN];
  119.  
  120.   /* Now set relevant values */
  121.   mac_img_width  = BYTES_LINE * 8;
  122.   mac_img_height = MAX_LINES;
  123.   mac_img_depth  = 1;        /* always monochrome */
  124.   mac_img_planes = 1;        /* always 1 */
  125.   mac_img_BPL    = BYTES_LINE;
  126.  
  127.   /* mac B/W bitmaps have a two entry colormap */
  128.   r[0] = g[0] = b[0] = 0;     /* 0 = black */
  129.   r[1] = g[1] = b[1] = 255;   /* 1 = white */
  130.  
  131.   return MACIN_SUCCESS;
  132. }
  133.  
  134. /*
  135.  * these are the routines added for interfacing to xloadimage
  136.  */
  137.  
  138. LoadMAC(fname, nc)
  139.      char *fname;
  140.      int  nc;
  141.   FILE *fp;
  142.   byte *picptr, ch;
  143.   register int scanLine, mask;
  144.   register unsigned int i, j, k;
  145.   register unsigned int x, y, c;
  146.   long filesize;
  147.   int maxpixels;
  148.   int value;
  149.  
  150.   fp = fopen(fname, "r");
  151.   if (!fp)
  152.     return(MacError("Couldn't open file"));
  153.  
  154.   /* figure out the filesize (for informational purposes only) */
  155.   fseek(fp, 0L, 2);
  156.   filesize = ftell(fp);
  157.   fseek(fp, 0L, 0);
  158.  
  159.   /*
  160.    * the +256's are so we can read truncated image
  161.    * files without fear of segmentation violation
  162.    */
  163.   if (!(ptr = RawMAC = (byte *) malloc(filesize+256)))
  164.     return(MacError("not enough memory to read mac file") );
  165.  
  166.   /*
  167.    * read in the entire file
  168.    */
  169.   if (fread(ptr, filesize, 1, fp) != 1) 
  170.     return(MacError("MAC data read failed") );
  171.   
  172.   if (mac_read_header(fp) != MACIN_SUCCESS)  /* read image header */
  173.     return (MacError("Couldn't read MAC Header"));
  174.  
  175.   /* load up the stuff XV expects us to load up */
  176.   SetISTR(ISTR_FORMAT, "MAC image  (%ld bytes)", filesize);
  177.  
  178.   pWIDE = mac_img_width;
  179.   pHIGH = mac_img_height;
  180.   maxpixels = pWIDE * pHIGH;
  181.  
  182.   pic = picptr = (byte *) calloc(maxpixels, sizeof(byte));
  183.   if (!pic)
  184.     return (MacError("not enough memory for 'pic'"));
  185.  
  186.   scanLine = 0; k = 0;
  187.  
  188.   while (scanLine < mac_img_height) {
  189.  
  190.     ch = (byte) NEXTBYTE; /* fgetc(fp);    * Count byte */
  191.     i = (unsigned int) ch;
  192.     if (ch < 0x80) {    /* Unpack next (I+1) chars as is */
  193.       for (j = 0; j <= i; j++) {
  194.     if (scanLine < mac_img_height) {
  195.           value = (byte) NEXTBYTE; /*fgetc(fp);*/ k++;
  196.           for (x = 0; x < 8; x++) {
  197.             mask = 0x80 >> (x & 7);
  198.             *(picptr++) = (value & mask) ? BLACK : WHITE;
  199.           }
  200.       if (!(k %= BYTES_LINE)) {
  201.         scanLine++;
  202.       }
  203.     }
  204.       }
  205.     } else {    /* Repeat next char (2's comp I) times */
  206.       ch = NEXTBYTE; /*fgetc(fp);*/
  207.       for (j = 0; j <= 256 - i; j++) {
  208.     if (scanLine < mac_img_height) {
  209.           value = (byte) ch; k++;
  210.           for (x = 0; x < 8; x++) {
  211.             mask = 0x80 >> (x & 7);
  212.             *(picptr++) = (value & mask) ? BLACK : WHITE;
  213.           }
  214.       if (!(k %= BYTES_LINE)) {
  215.         scanLine++;
  216.       }
  217.         }
  218.       }
  219.     }
  220.   }
  221.   if (fp != stdin)
  222.     fclose(fp);
  223.   if (RawMAC != NULL)
  224.     free(RawMAC);
  225.   return 0;
  226. }
  227.  
  228. /*****************************/
  229. static int MacError(st)
  230.      char *st;
  231. {
  232.   fprintf(stderr,"LoadMAC() - %s\n",st);
  233.   
  234.   if (pic != NULL) free(pic);
  235.   if (RawMAC != NULL) free(RawMAC);
  236.  
  237.   return -1;
  238. }
  239. ::::::::::::::
  240. inbox/11
  241. ::::::::::::::
  242. Return-Path: markm@sequent.com
  243. Posted-Date: Thu, 24 Oct 91 14:49:16 -0700
  244. Received-Date: Thu, 24 Oct 91 17:50:21 EDT
  245. Received: from time1.sequent.com by gateway.sequent.com (5.61/1.34)
  246.     id AA13012; Thu, 24 Oct 91 14:51:09 -0700
  247. Received: by time1.sequent.com (5.61/1.34)
  248.     id AA22604; Thu, 24 Oct 91 14:49:16 -0700
  249. Date: Thu, 24 Oct 91 14:49:16 -0700
  250. From: Mark Ed Majhor <markm@sequent.com>
  251. Message-Id: <9110242149.AA22604@time1.sequent.com>
  252. To: bradley@grip.cis.upenn.edu
  253. Subject: Re: Hi (I am an xv user) (whoops - here is xvmac.c include file)
  254.  
  255. /****************************************************************
  256.  * mac.h:
  257.  *
  258.  * adapted from code by Patrick Naughton (naughton@sun.soe.clarkson.edu)
  259.  *
  260.  * macin.h
  261.  * Mark Majhor
  262.  * August 1990
  263.  *
  264.  * routines for reading MAC files
  265.  *
  266.  ****************************************************************/
  267.  
  268. # define MAC_MAGIC    0x0
  269. # define BLACK        0
  270. # define WHITE        1
  271.  
  272. typedef unsigned char BYTE;    /* 8 bits unsigned        */
  273.  
  274. /*
  275.  * macin return codes
  276.  */
  277. #define MACIN_SUCCESS       0   /* success */
  278.  
  279. #define MACIN_ERR_BAD_SD   -1   /* bad screen descriptor */
  280. #define MACIN_ERR_BAD_SIG  -2   /* bad signature */
  281. #define MACIN_ERR_EOD      -3   /* unexpected end of raster data */
  282. #define MACIN_ERR_EOF      -4   /* unexpected end of input stream */
  283. #define MACIN_ERR_FAO      -5   /* file already open */
  284. #define MACIN_ERR_IAO      -6   /* image already open */
  285. #define MACIN_ERR_NFO      -7   /* no file open */
  286. #define MACIN_ERR_NIO      -8   /* no image open */
  287.  
  288. static int macin_open_image();
  289. static int macin_close_file();
  290. static int macin_fatal();
  291.  
  292. #define    MAC_HDR_LEN    512
  293. #define ADD_HDR_LEN    128
  294. #define    MAX_LINES    720
  295. #define    BYTES_LINE    72
  296.